
<!doctype html>
<html lang="en" class="no-js">
  <head>
    
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width,initial-scale=1">
      
      
      
      <link rel="icon" href="../../../../static/images/favicon.png">
      <meta name="generator" content="mkdocs-1.3.0, mkdocs-material-8.2.8">
    
    
      
        <title>Java Spring 应用在 kubernetes 环境下 JDK 内存配置采坑 - WL4G DOCS</title>
      
    
    
      <link rel="stylesheet" href="../../../../assets/stylesheets/main.644de097.min.css">
      
        
        <link rel="stylesheet" href="../../../../assets/stylesheets/palette.e6a45f82.min.css">
        
      
    
    
    
      
        
        
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
        <style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
      
    
    
      <link rel="stylesheet" href="../../../../static/css/util.css">
    
    <script>__md_scope=new URL("../../../..",location),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
    
      

    
    
  </head>
  
  
    
    
      
    
    
    
    
    <body dir="ltr" data-md-color-scheme="default" data-md-color-primary="" data-md-color-accent="">
  
    
    
      <script>var palette=__md_get("__palette");if(palette&&"object"==typeof palette.color)for(var key of Object.keys(palette.color))document.body.setAttribute("data-md-color-"+key,palette.color[key])</script>
    
    <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
    <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
    <label class="md-overlay" for="__drawer"></label>
    <div data-md-component="skip">
      
        
        <a href="#java-spring-kubernetes-jdk" class="md-skip">
          Skip to content
        </a>
      
    </div>
    <div data-md-component="announce">
      
    </div>
    
      <div data-md-component="outdated" hidden>
        <aside class="md-banner md-banner--warning">
          
        </aside>
      </div>
    
    
      

<header class="md-header" data-md-component="header">
  <nav class="md-header__inner md-grid" aria-label="Header">
    <a href="../../../.." title="WL4G DOCS" class="md-header__button md-logo" aria-label="WL4G DOCS" data-md-component="logo">
      
  <img src="../../../../static/images/mylogo.jpeg" alt="logo">

    </a>
    <label class="md-header__button md-icon" for="__drawer">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2z"/></svg>
    </label>
    <div class="md-header__title" data-md-component="header-title">
      <div class="md-header__ellipsis">
        <div class="md-header__topic">
          <span class="md-ellipsis">
            WL4G DOCS
          </span>
        </div>
        <div class="md-header__topic" data-md-component="header-topic">
          <span class="md-ellipsis">
            
              Java Spring 应用在 kubernetes 环境下 JDK 内存配置采坑
            
          </span>
        </div>
      </div>
    </div>
    
      <form class="md-header__option" data-md-component="palette">
        
          
          
          <input class="md-option" data-md-color-media="(prefers-color-scheme: light)" data-md-color-scheme="default" data-md-color-primary="" data-md-color-accent=""  aria-label="Switch to dark mode"  type="radio" name="__palette" id="__palette_1">
          
            <label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_2" hidden>
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 6H7c-3.31 0-6 2.69-6 6s2.69 6 6 6h10c3.31 0 6-2.69 6-6s-2.69-6-6-6zm0 10H7c-2.21 0-4-1.79-4-4s1.79-4 4-4h10c2.21 0 4 1.79 4 4s-1.79 4-4 4zM7 9c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/></svg>
            </label>
          
        
          
          
          <input class="md-option" data-md-color-media="(prefers-color-scheme: dark)" data-md-color-scheme="slate" data-md-color-primary="" data-md-color-accent=""  aria-label="Switch to light mode"  type="radio" name="__palette" id="__palette_2">
          
            <label class="md-header__button md-icon" title="Switch to light mode" for="__palette_1" hidden>
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 7H7a5 5 0 0 0-5 5 5 5 0 0 0 5 5h10a5 5 0 0 0 5-5 5 5 0 0 0-5-5m0 8a3 3 0 0 1-3-3 3 3 0 0 1 3-3 3 3 0 0 1 3 3 3 3 0 0 1-3 3z"/></svg>
            </label>
          
        
      </form>
    
    
      <div class="md-header__option">
        <div class="md-select">
          
          <button class="md-header__button md-icon" aria-label="Select language">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="m12.87 15.07-2.54-2.51.03-.03A17.52 17.52 0 0 0 14.07 6H17V4h-7V2H8v2H1v2h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04M18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12m-2.62 7 1.62-4.33L19.12 17h-3.24z"/></svg>
          </button>
          <div class="md-select__inner">
            <ul class="md-select__list">
              
                <li class="md-select__item">
                  <a href="/en/" hreflang="en" class="md-select__link">
                    English
                  </a>
                </li>
                
                <li class="md-select__item">
                  <a href="/zh/" hreflang="zh" class="md-select__link">
                    简体中文
                  </a>
                </li>
                
            </ul>
          </div>
        </div>
      </div>
    
    
      <label class="md-header__button md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
      </label>
      <div class="md-search" data-md-component="search" role="dialog">
  <label class="md-search__overlay" for="__search"></label>
  <div class="md-search__inner" role="search">
    <form class="md-search__form" name="search">
      <input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
      <label class="md-search__icon md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
      </label>
      <nav class="md-search__options" aria-label="Search">
        
        <button type="reset" class="md-search__icon md-icon" aria-label="Clear" tabindex="-1">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>
        </button>
      </nav>
      
        <div class="md-search__suggest" data-md-component="search-suggest"></div>
      
    </form>
    <div class="md-search__output">
      <div class="md-search__scrollwrap" data-md-scrollfix>
        <div class="md-search-result" data-md-component="search-result">
          <div class="md-search-result__meta">
            Initializing search
          </div>
          <ol class="md-search-result__list"></ol>
        </div>
      </div>
    </div>
  </div>
</div>
    
    
  </nav>
  
</header>
    
    <div class="md-container" data-md-component="container">
      
      
        
          
            
<nav class="md-tabs" aria-label="Tabs" data-md-component="tabs">
  <div class="md-tabs__inner md-grid">
    <ul class="md-tabs__list">
      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../../.." class="md-tabs__link">
        Getting Started
      </a>
    </li>
  

      
    </ul>
  </div>
</nav>
          
        
      
      <main class="md-main" data-md-component="main">
        <div class="md-main__inner md-grid">
          
            
              
              <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    

  


  

<nav class="md-nav md-nav--primary md-nav--lifted md-nav--integrated" aria-label="Navigation" data-md-level="0">
  <label class="md-nav__title" for="__drawer">
    <a href="../../../.." title="WL4G DOCS" class="md-nav__button md-logo" aria-label="WL4G DOCS" data-md-component="logo">
      
  <img src="../../../../static/images/mylogo.jpeg" alt="logo">

    </a>
    WL4G DOCS
  </label>
  
  <ul class="md-nav__list" data-md-scrollfix>
    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_1" data-md-state="indeterminate" type="checkbox" id="__nav_1" checked>
      
      
      
      
        <label class="md-nav__link" for="__nav_1">
          Getting Started
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" aria-label="Getting Started" data-md-level="1">
        <label class="md-nav__title" for="__nav_1">
          <span class="md-nav__icon md-icon"></span>
          Getting Started
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../../.." class="md-nav__link">
        Introduction
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../../../ABOUT_CN/" class="md-nav__link">
        About
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
  </ul>
</nav>
                  </div>
                </div>
              </div>
            
            
          
          <div class="md-content" data-md-component="content">
            <article class="md-content__inner md-typeset">
              
                


<h1 id="java-spring-kubernetes-jdk">Java Spring 应用在 kubernetes 环境下 JDK 内存配置采坑<a class="headerlink" href="#java-spring-kubernetes-jdk" title="Permanent link">&para;</a></h1>
<h2 id="1">1. 前言<a class="headerlink" href="#1" title="Permanent link">&para;</a></h2>
<ul>
<li>
<p><strong>问题背景：</strong></p>
</li>
<li>
<p>在微服务架构中，网关、注册中心、配置中心、服务追踪、认证中心等一系列组件部署到服务器中会占用一定的内存，还有各个业务服务，一部署单个服务可能就占个几百M，甚至上G。那这一系列组件和服务同时部署不得消耗更多的内存？为防止这些服务把系统资源耗尽导致宕机，我们不得不为这些服务配置一定的内存限制。</p>
</li>
<li>
<p>在 kubernetes 环境中，如果我们单单配置了<code>memory</code>的<code>limit</code> ，没有配置 Java 应用的JVM参数，那么在 Java 程序运行过程中可能会导致内存超过<code>memory</code>的<code>limit</code>，发送 OOM 错误。因此，部署Java 应用到 k8s 环境中时要配置JVM参数及k8s的<code>memory</code>的<code>limit</code>。</p>
</li>
<li>
<p><strong>解决方案：</strong></p>
</li>
<li>
<p>其中<code>MaxRAMPercentage</code>、<code>InitialRAMPercentage</code>、<code>MinRAMPercentage</code>这三个参数是<code>JDK8u191</code>为适容器环境新增的参数，类比<code>Xmx、Xms</code>，至于<code>-XX:InitialRAMFraction</code>、<code>-XX:MaxRAMFraction</code>、<code>-XX:MinRAMFraction</code>已经被标记为deprecated 。那么这几个参数有什么好处呢？</p>
</li>
<li>
<p>在容器环境下，可以给每个JVM实例所属POD分配任意大小的内存上限。如，给每个AccountService分配4G，给每个PaymentService分配8G。如此一来启动脚本就不好写成通用的了，指定3G也不是，6G也不是。但有了这几个参数，就可以在通用的启动脚本中指定75%，如：<code>-XX:MaxRAMPercentage=75 -XX:InitialRAMPercentage=75 -XX:MinRAMPercentage=75</code>，那么AccountService就相当于设置了-Xmx3g -Xms3g，而PaymentService相当于设置了-Xmx6g -Xms6g，是不是很赞。</p>
</li>
</ul>
<h2 id="2-jvm">2. JVM 配置差异<a class="headerlink" href="#2-jvm" title="Permanent link">&para;</a></h2>
<ul>
<li>随着 JAVA 版本不同，JVM 启动参数配置有所不同，如下表：</li>
</ul>
<table>
<thead>
<tr>
<th>JDK版本</th>
<th>JVM参数</th>
</tr>
</thead>
<tbody>
<tr>
<td>&lt;8u131</td>
<td>-Xms64m -Xmx128m</td>
</tr>
<tr>
<td>8u131-191</td>
<td>-XX:+UnlockExperimentalVMOptions、-XX:+UseCGroupMemoryLimitForHeap</td>
</tr>
<tr>
<td>&gt;8u191</td>
<td>-XX:UseContainerSupport（默认启用）、ActiveProcessorCount；百分比分配堆内存：MaxRAMPercentage、InitialRAMPercentage、MinRAMPercentage</td>
</tr>
</tbody>
</table>
<ul>
<li>
<p>JDK8 版本小于<code>131</code>时，启动JAVA程序时，添加参数<code>-Xms64m -Xmx128m</code>参数，在<code>java 8u131+</code> 和 <code>java 9+</code> 版本，添加两个参数：<code>-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap</code>，在 JDK8 版本高于<code>191</code>时，可以使用<code>MaxRAMPercentage</code>，其值介于 0.0 到 100.0 之间，默认值为 25.0。</p>
</li>
<li>
<p>查看JVM所有支持的参数及默认值(&gt;<code>JDK6 update 21</code>才支持)：<code>java -XX:+PrintFlagsFinal</code></p>
</li>
</ul>
<h2 id="3">3. 配置实践<a class="headerlink" href="#3" title="Permanent link">&para;</a></h2>
<h3 id="31-jdk-8u131">3.1 JDK 版本<code>8u131</code><a class="headerlink" href="#31-jdk-8u131" title="Permanent link">&para;</a></h3>
<ul>
<li>在<code>Dockerfile</code>文件中配置：</li>
</ul>
<div class="highlight"><pre><span></span><code><a id="__codelineno-0-1" name="__codelineno-0-1"></a><a href="#__codelineno-0-1"><span class="linenos" data-linenos="1 "></span></a>ENV JVM_OPTS -Xms256m -Xmx512m
<a id="__codelineno-0-2" name="__codelineno-0-2"></a><a href="#__codelineno-0-2"><span class="linenos" data-linenos="2 "></span></a>ENTRYPOINT <span class="nb">exec</span> java <span class="nv">$JVM_OPTS</span> -jar lanweihong.jar
</code></pre></div>
<ul>
<li>注：这两个参数只设置了分配给堆的大小，实际的memory limit应该比这个还要大。</li>
</ul>
<h3 id="32-java-8u131java-9">3.2 <code>java 8u131+</code>和<code>java 9+</code>版本<a class="headerlink" href="#32-java-8u131java-9" title="Permanent link">&para;</a></h3>
<ul>
<li>对于<code>java 8u131+</code>和<code>java 9+</code>版本，在<code>Dockerfile</code>文件中，设置环境变量：</li>
</ul>
<div class="highlight"><pre><span></span><code><a id="__codelineno-1-1" name="__codelineno-1-1"></a><a href="#__codelineno-1-1"><span class="linenos" data-linenos="1 "></span></a>ENV JVM_OPTS -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction<span class="o">=</span><span class="m">2</span>
<a id="__codelineno-1-2" name="__codelineno-1-2"></a><a href="#__codelineno-1-2"><span class="linenos" data-linenos="2 "></span></a>ENTRYPOINT <span class="nb">exec</span> java <span class="nv">$JVM_OPTS</span> -jar lanweihong.jar
</code></pre></div>
<ul>
<li>其中<code>-XX:+UnlockExperimentalVMOptions</code>、<code>-XX:+UseCGroupMemoryLimitForHeap</code>设置<code>-XX:MaxRAM</code>为<code>cgroup</code> 的内存限制，这里的<code>-XX:MaxRAMFraction</code>值为<code>2</code>，那么 JVM 允许分配的内存为 <code>MaxRAM / MaxRAMFraction=4G/2=2G</code>，不设置为 <code>1</code> 是防止JVM占用所有的内存，导致其他进程(如Shell、MySQL等)没有可用内存。</li>
</ul>
<h3 id="33-jdk-8u191">3.3 JDK版本 8u191+<a class="headerlink" href="#33-jdk-8u191" title="Permanent link">&para;</a></h3>
<ul>
<li>在<code>Dockerfile</code>文件中配置：</li>
</ul>
<div class="highlight"><pre><span></span><code><a id="__codelineno-2-1" name="__codelineno-2-1"></a><a href="#__codelineno-2-1"><span class="linenos" data-linenos="1 "></span></a>ENV JVM_OPTS -Xms256m -Xmx512m
<a id="__codelineno-2-2" name="__codelineno-2-2"></a><a href="#__codelineno-2-2"><span class="linenos" data-linenos="2 "></span></a>ENTRYPOINT <span class="nb">exec</span> java <span class="nv">$JVM_OPTS</span> -jar lanweihong.jar
</code></pre></div>
<ul>
<li>设置 JVM 可用的内存为总内存的 80%，显然这种方式更加灵活方便，也更安全。
如果使用 jib-maven-plugin 打包的，可以在 pom.xml 中添加配置:</li>
</ul>
<div class="highlight"><pre><span></span><code><a id="__codelineno-3-1" name="__codelineno-3-1"></a><a href="#__codelineno-3-1"><span class="linenos" data-linenos="1 "></span></a><span class="nt">&lt;container&gt;</span>
<a id="__codelineno-3-2" name="__codelineno-3-2"></a><a href="#__codelineno-3-2"><span class="linenos" data-linenos="2 "></span></a>    <span class="nt">&lt;mainClass&gt;</span>com.lanweihong.gateway.GatewayApplication<span class="nt">&lt;/mainClass&gt;</span>
<a id="__codelineno-3-3" name="__codelineno-3-3"></a><a href="#__codelineno-3-3"><span class="linenos" data-linenos="3 "></span></a>    <span class="cm">&lt;!-- 添加 jvm 参数 --&gt;</span>
<a id="__codelineno-3-4" name="__codelineno-3-4"></a><a href="#__codelineno-3-4"><span class="linenos" data-linenos="4 "></span></a>    <span class="nt">&lt;jvmFlags&gt;</span>
<a id="__codelineno-3-5" name="__codelineno-3-5"></a><a href="#__codelineno-3-5"><span class="linenos" data-linenos="5 "></span></a>        <span class="nt">&lt;jvmFlag&gt;</span>-XX:MaxRAMPercentage=80.0<span class="nt">&lt;/jvmFlag&gt;</span>
<a id="__codelineno-3-6" name="__codelineno-3-6"></a><a href="#__codelineno-3-6"><span class="linenos" data-linenos="6 "></span></a>    <span class="nt">&lt;/jvmFlags&gt;</span>
<a id="__codelineno-3-7" name="__codelineno-3-7"></a><a href="#__codelineno-3-7"><span class="linenos" data-linenos="7 "></span></a><span class="nt">&lt;/container&gt;</span>
</code></pre></div>
<ul>
<li>执行效果等同于 <code>java -XX:MaxRAMPercentage=80.0</code></li>
</ul>
<h3 id="34-kubernetes">3.4 Kubernetes 配置<a class="headerlink" href="#34-kubernetes" title="Permanent link">&para;</a></h3>
<ul>
<li>设置内存 limit 在 k8s 部署配置文件添加：</li>
</ul>
<div class="highlight"><pre><span></span><code><a id="__codelineno-4-1" name="__codelineno-4-1"></a><a href="#__codelineno-4-1"><span class="linenos" data-linenos=" 1 "></span></a><span class="nt">containers</span><span class="p">:</span><span class="w"></span>
<a id="__codelineno-4-2" name="__codelineno-4-2"></a><a href="#__codelineno-4-2"><span class="linenos" data-linenos=" 2 "></span></a><span class="w">    </span><span class="nt">resources</span><span class="p">:</span><span class="w"></span>
<a id="__codelineno-4-3" name="__codelineno-4-3"></a><a href="#__codelineno-4-3"><span class="linenos" data-linenos=" 3 "></span></a><span class="w">      </span><span class="nt">requests</span><span class="p">:</span><span class="w"></span>
<a id="__codelineno-4-4" name="__codelineno-4-4"></a><a href="#__codelineno-4-4"><span class="linenos" data-linenos=" 4 "></span></a><span class="w">        </span><span class="nt">memory</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;512Mi&quot;</span><span class="w"></span>
<a id="__codelineno-4-5" name="__codelineno-4-5"></a><a href="#__codelineno-4-5"><span class="linenos" data-linenos=" 5 "></span></a><span class="w">        </span><span class="c1"># cpu: &quot;500m&quot;</span><span class="w"></span>
<a id="__codelineno-4-6" name="__codelineno-4-6"></a><a href="#__codelineno-4-6"><span class="linenos" data-linenos=" 6 "></span></a><span class="w">      </span><span class="nt">limits</span><span class="p">:</span><span class="w"></span>
<a id="__codelineno-4-7" name="__codelineno-4-7"></a><a href="#__codelineno-4-7"><span class="linenos" data-linenos=" 7 "></span></a><span class="w">        </span><span class="nt">memory</span><span class="p">:</span><span class="w"> </span><span class="s">&quot;512Mi&quot;</span><span class="w"></span>
<a id="__codelineno-4-8" name="__codelineno-4-8"></a><a href="#__codelineno-4-8"><span class="linenos" data-linenos=" 8 "></span></a><span class="w">        </span><span class="c1"># cpu: &quot;500m&quot;</span><span class="w"></span>
<a id="__codelineno-4-9" name="__codelineno-4-9"></a><a href="#__codelineno-4-9"><span class="linenos" data-linenos=" 9 "></span></a><span class="w">    </span><span class="nt">env</span><span class="p">:</span><span class="w"></span>
<a id="__codelineno-4-10" name="__codelineno-4-10"></a><a href="#__codelineno-4-10"><span class="linenos" data-linenos="10 "></span></a><span class="w">      </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">JVM_OPTS</span><span class="w"></span>
<a id="__codelineno-4-11" name="__codelineno-4-11"></a><a href="#__codelineno-4-11"><span class="linenos" data-linenos="11 "></span></a><span class="w">        </span><span class="nt">values</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">-XX:MaxRAMPercentage=80.0</span><span class="w"></span>
</code></pre></div>
<ul>
<li>使用 <code>kubectl apply -f</code> 更新发布服务。</li>
</ul>
<h2 id="4">4. 总结<a class="headerlink" href="#4" title="Permanent link">&para;</a></h2>
<ul>
<li>JDK8 版本低于<code>191</code>的建议升级到最新版本，或<code>191</code>以后，<code>Java 8u191</code>和<code>Java 10+</code>支持 UserContainerSupport，设置JVM启动参数<code>MaxRAMPercentage</code>，具体的值根据情况来设置；
不升级JDK版本的，根据JDK版本按以上说明配置；
Kubernetes 配置 Limit。</li>
</ul>
<h2 id="5">5. 参考<a class="headerlink" href="#5" title="Permanent link">&para;</a></h2>
<ul>
<li>
<p><a href="https://blog.lanweihong.com/posts/33493/">参考原文连接1：https://blog.lanweihong.com/posts/33493/</a></p>
</li>
<li>
<p>[参考原文连接2：https://www.cnblogs.com/fengjian2016/p/13639411.html)</p>
</li>
<li>
<p><a href="https://www.baeldung.com/ops/docker-jvm-heap-size">How To Configure Java Heap Size Inside a Docker Container</a></p>
</li>
<li>
<p><a href="https://blog.51cto.com/daisywei/2697536">Kubernetes_pod_javajdk_动态JVM堆内存大小限制</a></p>
</li>
</ul>

              
            </article>
          </div>
        </div>
        
      </main>
      
        <footer class="md-footer">
  
  <div class="md-footer-meta md-typeset">
    <div class="md-footer-meta__inner md-grid">
      <div class="md-copyright">
  
  
    Made with
    <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
      Material for MkDocs
    </a>
  
</div>
      
    </div>
  </div>
</footer>
      
    </div>
    <div class="md-dialog" data-md-component="dialog">
      <div class="md-dialog__inner md-typeset"></div>
    </div>
    <script id="__config" type="application/json">{"base": "../../../..", "features": ["search.suggest", "search.highlight", "navigation.tabs", "navigation.expand", "toc.follow", "toc.integrate"], "search": "../../../../assets/javascripts/workers/search.5e67fbfe.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.config.lang": "en", "search.config.pipeline": "trimmer, stopWordFilter", "search.config.separator": "[\\s\\-]+", "search.placeholder": "Search", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version.title": "Select version"}, "version": {"default": "latest", "provider": "mike"}}</script>
    
    
      <script src="../../../../assets/javascripts/bundle.c44cc438.min.js"></script>
      
        <script src="../../../../static/js/util.js"></script>
      
    
  </body>
</html>